<template>
  <div class="tlCollapseWrapper">
    <div class="tl-collapse">
      <div class="tl-collapse__text is-left border">
        <span style="margin-left:3px">{{ text }}</span>
      </div>
      <svg-icon
        :icon-class="inCollapsed ? 'arrow-right' : 'arrow-down'"
        class="tl-collapse__text is-right icon"
        @click="handleCollapse"
      />
    </div>

    <!-- <el-collapse-transition> -->
    <div v-show="!inCollapsed" style="margin-bottom: 20px;">
      <slot>content</slot>
    </div>
    <!-- </el-collapse-transition> -->
  </div>
</template>

<script>
export default {
  name: 'TlCollapse',
  props: {
    text: {
      type: String,
      default: ''
    },
    // 折叠
    collapsed: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      inCollapsed: this.collapsed
    }
  },
  methods: {
    handleCollapse() {
      this.inCollapsed = !this.inCollapsed
    }
  }
}
</script>

<style lang="scss" scoped>
.tlCollapseWrapper {
  padding-top: 3px;
}
.tl-collapse {
  display: block;
  height: 1px;
  width: 100%;
  margin: 16px 0;

  background-color: #d7d7d7;
  position: relative;

  &__text {
    position: absolute;
    background-color: #fff;
    font-weight: 500;
    color: #686869;
    font-size: 14px;
    user-select: none;
  }
}

.border {
  border-left: 3px;
  border-left: 4px solid #1890ff;
}

.is-left {
  left: 0px;
  transform: translateY(-50%);
}

.is-right {
  right: 0px;
  transform: translateY(-50%);
}

.icon {
  font-size: 18px;
  cursor: pointer;
}
</style>
